#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>


struct TreeNode {
	int val;
	struct TreeNode* left;
	struct TreeNode* right;
};

typedef struct TreeNode TNode;

void findLeftLeaves(TNode* root, int* arr, int* psize)
{
	if (root == NULL)
	{
		return;
	}
	if (root->left)
	{
		if ((root->left->left == NULL) && (root->left->right == NULL))
		{
			arr[(*psize)++] = root->left->val;
		}
	}
	findLeftLeaves(root->left, arr, psize);
	findLeftLeaves(root->right, arr, psize);
	return;
}

int sumOfLeftLeaves(struct TreeNode* root) {
	int arr[1000] = { 0 };
	int size = 0;
	int ret = 0;
	findLeftLeaves(root, arr, &size);
	for (int i = 0; i < size; i++)
	{
		ret += arr[i];
	}
	return ret;
}

int ysf1(int n, int m) {
	int arr[10001] = { 0 };
	int size = n;
	int i = 0;
	for (i = 1; i <= n; i++)
	{
		arr[i] = i;
	}
	while (size > 1)
	{
		i = 1;
		int numofrem = 0;
		while (i <= n && size > 1)
		{
			if (arr[i] && (arr[i] % m))
			{
				arr[i] += size;
				numofrem++;
				if (numofrem == size)
					break;
			}
			else if (arr[i] && (arr[i] % m == 0))
			{
				arr[i] = 0;
				size--;
			}
			i++;
		}
	}
	for (i = 1; i <= n; i++) {
		if (arr[i])
			return i;
	}
	return i;
}

int ysf2(int n, int m)
{

}

int main()
{
	//TNode* n1 = (TNode*)malloc(sizeof(TNode));
	//TNode* n2 = (TNode*)malloc(sizeof(TNode));
	//TNode* n3 = (TNode*)malloc(sizeof(TNode));
	//TNode* n4 = (TNode*)malloc(sizeof(TNode));
	//TNode* n5 = (TNode*)malloc(sizeof(TNode));
	//TNode* n6 = (TNode*)malloc(sizeof(TNode));
	//TNode* n7 = (TNode*)malloc(sizeof(TNode));
	//TNode* n8 = (TNode*)malloc(sizeof(TNode));
	//TNode* n9 = (TNode*)malloc(sizeof(TNode));
	//TNode* n10 = (TNode*)malloc(sizeof(TNode));

	//n1->val = 3;
	//n2->val = 9;
	//n3->val = 20;
	//n4->val = 15;
	//n5->val = 7;
	//n6->val = 1;
	//n7->val = 2;
	//n8->val = 5;
	//n9->val = 5;
	//n10->val = 6;

	//n1->left = n2;
	//n1->right = n3;

	//n2->left = NULL;
	//n2->right = NULL;

	//n3->left = n4;
	//n3->right = n5;

	//n4->left = NULL;
	//n4->right = NULL;

	//n5->left = NULL;
	//n5->right = NULL;

	//n6->left = n8;
	//n6->right = NULL;

	//n7->left = n9;
	//n7->right = NULL;

	//n8->left = n10;
	//n8->right = NULL;

	//n9->left = NULL;
	//n9->right = NULL;

	//n10->left = NULL;
	//n10->right = NULL;

	//TNode* phead = n1;

	//int ret = sumOfLeftLeaves(n1);





	int a = 43;
	int b = 9001;
	

	return 0;
}